import React, { Component } from "react"
import { Select } from "antd"
import { getChannels } from "api/channels"
const { Option } = Select

export default class Channel extends Component {
  state = {
    channels: []
  }
  componentDidMount() {
    this.getChannelList()
  }
  // 获取频道列表
  async getChannelList() {
    const res = await getChannels()
    // console.log("频道", res)
    this.setState({
      channels: res.data.channels
    })
  }
  render() {
    // console.log(this.props)
    return (
      <Select
        style={{ width: 200 }}
        placeholder="请选择文章频道"
        value={this.props.value}
        onChange={this.props.onChange}>
        {this.state.channels.map(item => (
          <Option key={item.id} value={item.id}>
            {item.name}
          </Option>
        ))}
      </Select>
    )
  }
}
